<template>
    <div class="user">
        <commonUserinfo :userInfoData="{userItemIndex:itemIndex,userLeftHeight:userLeftHeight,$parent:$parent}">
            <div class="user_main_right f_left text_center">
                <div class="user_right_tip">
                    温馨提示：在线报名和继续教育<br>
                    报名之前必须先完善个人信息
                </div>
                <div class="user_userInfo color666">
                    <dl>
                        <dt class="f_left">真实姓名：</dt>
                        <dd class="f_left">{{form.realName}}</dd>
                    </dl>
                    <dl>
                        <dt class="f_left">身份证号：</dt>
                        <dd class="f_left">{{form.remark}}</dd>
                    </dl>
                    <dl>
                        <dt class="f_left">手机号码：</dt>
                        <dd class="f_left">{{form.encryptTelphone}}</dd>
                    </dl>
                    <dl>
                        <dt class="f_left">所在企业：</dt>
                        <dd class="f_left">{{form.companyName}}</dd>
                    </dl>
                </div>

                <el-button type="primary" class="my_modify" @click="updateCompany=true">申请修改企业</el-button>
                <el-button type="primary" class="my_modify" @click="updateName=true">申请修改姓名</el-button>
                <p style="color: #ff0000;margin-top: 30px;">注：申请修改的信息将在审核通过后再新的报名中体现，审核结果请在<router-link to="/user/business_center">业务中心</router-link>查看申请结果。</p>
                <el-dialog title="申请修改企业" :visible.sync="updateCompany">
                    <el-form>
                        <el-form-item label="企业名称" label-width="120px">
                            <el-input v-model.trim="modifyInfo.companyName" placeholder="请输入要修改企业的完整名称"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="updateCompany = false">取 消</el-button>
                        <el-button type="primary" @click="modifyDefine()">确 定</el-button>
                    </div>
                </el-dialog>

                <el-dialog title="申请修改姓名" :visible.sync="updateName">
                    <el-form>
                        <el-form-item label="姓名" label-width="120px">
                            <el-input v-model.trim="modifyInfo.changeName" placeholder="请输入要修改的姓名"></el-input>
                        </el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="updateName = false">取 消</el-button>
                        <el-button type="primary" @click="updateNameSubmit()">确 定</el-button>
                    </div>
                </el-dialog>
            </div>
        </commonUserinfo>
    </div>
</template>

<script>
    var _this;
    import commonUserinfo from '@/components/c_userinfo.vue'
    export default {
        name: "user_info",
        data() {
            return {
                typePage: "userInfo",
                form: {},
                itemIndex: 0,
                userLeftHeight: '',
                updateCompany: false,
                updateName: false,
                modifyInfo: {
                    companyName: '',
                    changeName: ''
                },
                updateNum: 0
            }
        },
        beforeCreate: function() {
            _this = this;
        },
        mounted: function() {
            this.common.post(this.api.getMyInfo, {}, function(res) {
                _this.form = res.resultMap;
            });
        },
        methods: {
            modifyDefine() {
                if(this.modifyInfo.companyName.length>50){
                    this.$message.error("输入内容不能超过50字！");
                    return;
                }
                this.common.post(this.api.applyChangeCompany, this.modifyInfo, res => {
                    this.$message.success("申请已提交！");
                    this.updateCompany = false;
                    this.modifyInfo.companyName = "";
                }, error => {
                    this.$message.error(error.resultMsg);
                });
            },
            updateNameSubmit(){
                if(this.modifyInfo.companyName.length>50){
                    this.$message.error("输入内容不能超过50字！");
                    return;
                }
                if(this.modifyInfo.changeName==""){
                    this.$message.error("请输入要修改的姓名！");
                    return;
                }
                this.common.post(this.api.applyChangeUserName, this.modifyInfo, res => {
                    _this.$message.success("申请已提交！");
                    _this.updateName = false;
                    _this.modifyInfo.changeName = "";
                }, error => {
                    _this.$message.error(error.resultMsg);
                });
            }
        },
        components: {
            commonUserinfo
        }
    }
</script>

<style>
    .my_modify {
        margin-top: 30px;
    }
</style>
